//
// Decompiled by Jadx - 648ms
//
package fo;

import android.annotation.SuppressLint;
import android.text.TextUtils;
import com.google.gson.Gson;
import fn.a;
import fn.j;
import fn.y;
import java.util.AbstractCollection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import me.plusne.common.Json.JsonHookStatic;
import org.luckypray.dexkit.DexKitBridge;
import org.luckypray.dexkit.query.FindClass;
import org.luckypray.dexkit.query.FindField;
import org.luckypray.dexkit.query.FindMethod;
import org.luckypray.dexkit.query.matchers.ClassMatcher;
import org.luckypray.dexkit.query.matchers.FieldMatcher;
import org.luckypray.dexkit.query.matchers.MethodMatcher;
import org.luckypray.dexkit.result.ClassData;
import org.luckypray.dexkit.result.ClassDataList;
import org.luckypray.dexkit.result.FieldData;
import org.luckypray.dexkit.result.FieldDataList;
import org.luckypray.dexkit.result.MethodData;
import org.luckypray.dexkit.result.MethodDataList;

@SuppressLint({"DuplicateCreateDexKit"})
public final class c extends a {
    public static boolean k;
    public static final HashMap<String, Object> l = new HashMap<>();

    public static synchronized MethodData aa(String str) {
        FindMethod findMethod;
        MethodMatcher matcher;
        MethodData q;
        synchronized (c.class) {
            DexKitBridge bridge = y.by.getBridge();
            String cj = y.cj(str.trim());
            if (!TextUtils.isEmpty(cj) && (findMethod = (FindMethod) new Gson().fromJson(cj, FindMethod.class)) != null) {
                matcher = findMethod.getMatcher();
                q = q(bridge, matcher, 0);
            }
            matcher = null;
            q = q(bridge, matcher, 0);
        }
        return q;
    }

    public static synchronized ClassData m(DexKitBridge dexKitBridge, ClassMatcher classMatcher) {
        boolean z;
        synchronized (c.class) {
            System.currentTimeMillis();
            String a = a.a();
            Object obj = l.get(a + "_ClassData");
            if (obj != null) {
                return (ClassData) obj;
            }
            JsonHookStatic jsonHookStatic = y.by;
            ClassData classData = null;
            if (jsonHookStatic.getBridge() == null) {
                j.bi(new Object[]{"Bridge not initialized!"});
                return null;
            }
            if (jsonHookStatic.getBridge().isValid()) {
                z = false;
            } else {
                jsonHookStatic.setBridge(k ? DexKitBridge.create(jsonHookStatic.getClassLoader(), true) : DexKitBridge.create(jsonHookStatic.getLpparam().appInfo.sourceDir));
                dexKitBridge = jsonHookStatic.getBridge();
                z = true;
            }
            try {
                classData = a.b(a);
                if (classData == null) {
                    ClassDataList findClass = dexKitBridge.findClass(FindClass.create().matcher(classMatcher));
                    if (!findClass.isEmpty()) {
                        classData = (ClassData) findClass.get(0);
                    }
                }
                if (classData != null) {
                    a.j(a, classData.getDescriptor());
                }
            } catch (IllegalStateException e) {
                e.printStackTrace();
                j.bi(new Object[]{e});
            }
            if (z) {
                y.by.getBridge().close();
            }
            if (classData != null) {
                l.put(a + "_ClassData", classData);
            } else {
                j.bi(new Object[]{"error", a + "\n" + new Gson().toJson(classMatcher)});
            }
            return classData;
        }
    }

    public static synchronized ClassData n(ClassMatcher classMatcher) {
        ClassData m;
        synchronized (c.class) {
            m = m(y.by.getBridge(), classMatcher);
        }
        return m;
    }

    public static synchronized FieldData o(Object obj, FieldMatcher fieldMatcher, int i) {
        boolean z;
        synchronized (c.class) {
            System.currentTimeMillis();
            String a = a.a();
            Object obj2 = l.get(a + "_FieldData");
            if (obj2 != null) {
                return (FieldData) obj2;
            }
            JsonHookStatic jsonHookStatic = y.by;
            FieldData fieldData = null;
            if (jsonHookStatic.getBridge() == null) {
                j.bi(new Object[]{"Bridge not initialized!"});
                return null;
            }
            if (jsonHookStatic.getBridge().isValid()) {
                z = false;
            } else {
                jsonHookStatic.setBridge(k ? DexKitBridge.create(jsonHookStatic.getClassLoader(), true) : DexKitBridge.create(jsonHookStatic.getLpparam().appInfo.sourceDir));
                obj = jsonHookStatic.getBridge();
                z = true;
            }
            try {
                fieldData = a.d(a);
                if (fieldData == null) {
                    FieldDataList findField = obj instanceof DexKitBridge ? ((DexKitBridge) obj).findField(FindField.create().matcher(fieldMatcher)) : ((FieldDataList) obj).findField(FindField.create().matcher(fieldMatcher));
                    if (!findField.isEmpty()) {
                        fieldData = (FieldData) findField.get(i);
                    }
                }
                if (fieldData != null) {
                    a.j(a, fieldData.getDescriptor());
                }
            } catch (IllegalStateException e) {
                e.printStackTrace();
                j.bi(new Object[]{e});
            }
            if (z) {
                y.by.getBridge().close();
            }
            if (fieldData != null) {
                l.put(a + "_FieldData", fieldData);
            } else {
                j.bi(new Object[]{"error", a + "\n" + a, new Gson().toJson(fieldMatcher)});
            }
            return fieldData;
        }
    }

    public static synchronized FieldData p(FieldMatcher fieldMatcher) {
        FieldData o;
        synchronized (c.class) {
            o = o(y.by.getBridge(), fieldMatcher, 0);
        }
        return o;
    }

    /* JADX WARN: Removed duplicated region for block: B:33:0x00c1 A[Catch: IllegalStateException -> 0x00c9, all -> 0x0123, TRY_ENTER, TRY_LEAVE, TryCatch #0 {, blocks: (B:4:0x0003, B:10:0x000f, B:12:0x0028, B:15:0x002c, B:17:0x0036, B:20:0x0041, B:22:0x004b, B:24:0x004f, B:25:0x0057, B:26:0x0068, B:29:0x006f, B:43:0x0075, B:45:0x0079, B:47:0x00ad, B:49:0x00b3, B:33:0x00c1, B:36:0x00d6, B:38:0x00e1, B:41:0x00f8, B:52:0x0088, B:54:0x008c, B:56:0x009d, B:59:0x00ca, B:61:0x005b), top: B:3:0x0003 }] */
    /* JADX WARN: Removed duplicated region for block: B:36:0x00d6 A[Catch: all -> 0x0123, TryCatch #0 {, blocks: (B:4:0x0003, B:10:0x000f, B:12:0x0028, B:15:0x002c, B:17:0x0036, B:20:0x0041, B:22:0x004b, B:24:0x004f, B:25:0x0057, B:26:0x0068, B:29:0x006f, B:43:0x0075, B:45:0x0079, B:47:0x00ad, B:49:0x00b3, B:33:0x00c1, B:36:0x00d6, B:38:0x00e1, B:41:0x00f8, B:52:0x0088, B:54:0x008c, B:56:0x009d, B:59:0x00ca, B:61:0x005b), top: B:3:0x0003 }] */
    /* JADX WARN: Removed duplicated region for block: B:38:0x00e1 A[Catch: all -> 0x0123, TryCatch #0 {, blocks: (B:4:0x0003, B:10:0x000f, B:12:0x0028, B:15:0x002c, B:17:0x0036, B:20:0x0041, B:22:0x004b, B:24:0x004f, B:25:0x0057, B:26:0x0068, B:29:0x006f, B:43:0x0075, B:45:0x0079, B:47:0x00ad, B:49:0x00b3, B:33:0x00c1, B:36:0x00d6, B:38:0x00e1, B:41:0x00f8, B:52:0x0088, B:54:0x008c, B:56:0x009d, B:59:0x00ca, B:61:0x005b), top: B:3:0x0003 }] */
    /* JADX WARN: Removed duplicated region for block: B:41:0x00f8 A[Catch: all -> 0x0123, TRY_LEAVE, TryCatch #0 {, blocks: (B:4:0x0003, B:10:0x000f, B:12:0x0028, B:15:0x002c, B:17:0x0036, B:20:0x0041, B:22:0x004b, B:24:0x004f, B:25:0x0057, B:26:0x0068, B:29:0x006f, B:43:0x0075, B:45:0x0079, B:47:0x00ad, B:49:0x00b3, B:33:0x00c1, B:36:0x00d6, B:38:0x00e1, B:41:0x00f8, B:52:0x0088, B:54:0x008c, B:56:0x009d, B:59:0x00ca, B:61:0x005b), top: B:3:0x0003 }] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static synchronized MethodData q(Object obj, MethodMatcher methodMatcher, int i) {
        boolean z;
        MethodData g;
        synchronized (c.class) {
            String a = a.a();
            System.currentTimeMillis();
            MethodData methodData = null;
            if (methodMatcher == null) {
                return null;
            }
            Object obj2 = l.get(a + "_MethodData");
            if (obj2 != null) {
                return (MethodData) obj2;
            }
            JsonHookStatic jsonHookStatic = y.by;
            if (jsonHookStatic.getBridge() == null) {
                j.bi(new Object[]{"Bridge not initialized!"});
                return null;
            }
            if (jsonHookStatic.getBridge().isValid()) {
                z = false;
            } else {
                jsonHookStatic.setBridge(k ? DexKitBridge.create(jsonHookStatic.getClassLoader(), true) : DexKitBridge.create(jsonHookStatic.getLpparam().appInfo.sourceDir));
                obj = jsonHookStatic.getBridge();
                z = true;
            }
            try {
                g = a.g(a);
            } catch (IllegalStateException e) {
                e = e;
            }
            if (g == null) {
                try {
                    if (obj instanceof DexKitBridge) {
                        methodData = ((DexKitBridge) obj).findMethod(FindMethod.create().matcher(methodMatcher));
                    } else if (obj instanceof MethodDataList) {
                        methodData = ((MethodDataList) obj).findMethod(FindMethod.create().matcher(methodMatcher));
                    } else if (obj != null) {
                        methodData = ((ClassData) obj).findMethod(FindMethod.create().matcher(methodMatcher));
                    }
                } catch (IllegalStateException e2) {
                    e = e2;
                    methodData = g;
                    e.printStackTrace();
                    j.bi(new Object[]{e});
                    if (z) {
                    }
                    if (methodData != null) {
                    }
                    return methodData;
                }
                if (methodData != null && !methodData.isEmpty()) {
                    methodData = (MethodData) methodData.get(i);
                    if (methodData != null) {
                        a.j(a, methodData.getDescriptor());
                    }
                    if (z) {
                        y.by.getBridge().close();
                    }
                    if (methodData != null) {
                        l.put(a + "_MethodData", methodData);
                    } else {
                        j.bi(new Object[]{"error", a + "\n" + new Gson().toJson(methodMatcher)});
                    }
                    return methodData;
                }
            }
            methodData = g;
            if (methodData != null) {
            }
            if (z) {
            }
            if (methodData != null) {
            }
            return methodData;
        }
    }

    public static synchronized MethodData r(MethodMatcher methodMatcher) {
        MethodData q;
        synchronized (c.class) {
            q = q(y.by.getBridge(), methodMatcher, 1);
        }
        return q;
    }

    public static synchronized FieldData s(FieldMatcher fieldMatcher) {
        FieldData o;
        synchronized (c.class) {
            o = o(y.by.getBridge(), fieldMatcher, 1);
        }
        return o;
    }

    public static synchronized MethodData t(MethodMatcher methodMatcher) {
        MethodData q;
        synchronized (c.class) {
            q = q(y.by.getBridge(), methodMatcher, 0);
        }
        return q;
    }

    public static synchronized ClassData u() {
        FindClass findClass;
        ClassMatcher matcher;
        ClassData m;
        synchronized (c.class) {
            DexKitBridge bridge = y.by.getBridge();
            String cj = y.cj("auto_play_class");
            if (!TextUtils.isEmpty(cj) && (findClass = (FindClass) new Gson().fromJson(cj, FindClass.class)) != null) {
                matcher = findClass.getMatcher();
                m = m(bridge, matcher);
            }
            matcher = null;
            m = m(bridge, matcher);
        }
        return m;
    }

    public static synchronized ClassDataList v(DexKitBridge dexKitBridge, ClassMatcher classMatcher) {
        boolean z;
        synchronized (c.class) {
            System.currentTimeMillis();
            String a = a.a();
            Object obj = l.get(a + "_ClassDataList");
            if (obj != null) {
                return (ClassDataList) obj;
            }
            JsonHookStatic jsonHookStatic = y.by;
            AbstractCollection abstractCollection = null;
            if (jsonHookStatic.getBridge() == null) {
                j.bi(new Object[]{"Bridge not initialized!"});
                return null;
            }
            if (jsonHookStatic.getBridge().isValid()) {
                z = false;
            } else {
                jsonHookStatic.setBridge(k ? DexKitBridge.create(jsonHookStatic.getClassLoader(), true) : DexKitBridge.create(jsonHookStatic.getLpparam().appInfo.sourceDir));
                dexKitBridge = jsonHookStatic.getBridge();
                z = true;
            }
            try {
                abstractCollection = a.c(a);
                if (abstractCollection == null) {
                    abstractCollection = dexKitBridge.findClass(FindClass.create().matcher(classMatcher));
                }
                ArrayList arrayList = new ArrayList();
                Iterator it = abstractCollection.iterator();
                while (it.hasNext()) {
                    arrayList.add(((ClassData) it.next()).getDescriptor());
                }
                a.j(a, new Gson().toJson(arrayList));
            } catch (IllegalStateException e) {
                e.printStackTrace();
                j.bi(new Object[]{e});
            }
            if (z) {
                y.by.getBridge().close();
            }
            if (abstractCollection != null) {
                l.put(a + "_ClassDataList", abstractCollection);
            } else {
                j.bi(new Object[]{"error", a + "\n" + new Gson().toJson(classMatcher)});
            }
            return abstractCollection;
        }
    }

    public static synchronized FieldDataList w(DexKitBridge dexKitBridge, FieldMatcher fieldMatcher) {
        boolean z;
        synchronized (c.class) {
            System.currentTimeMillis();
            String a = a.a();
            Object obj = l.get("_FieldData");
            if (obj != null) {
                return (FieldDataList) obj;
            }
            JsonHookStatic jsonHookStatic = y.by;
            AbstractCollection abstractCollection = null;
            if (jsonHookStatic.getBridge() == null) {
                j.bi(new Object[]{"Bridge not initialized!"});
                return null;
            }
            if (jsonHookStatic.getBridge().isValid()) {
                z = false;
            } else {
                jsonHookStatic.setBridge(k ? DexKitBridge.create(jsonHookStatic.getClassLoader(), true) : DexKitBridge.create(jsonHookStatic.getLpparam().appInfo.sourceDir));
                dexKitBridge = jsonHookStatic.getBridge();
                z = true;
            }
            try {
                abstractCollection = a.e(a);
                if (abstractCollection == null) {
                    abstractCollection = dexKitBridge.findField(FindField.create().matcher(fieldMatcher));
                }
                ArrayList arrayList = new ArrayList();
                Iterator it = abstractCollection.iterator();
                while (it.hasNext()) {
                    arrayList.add(((FieldData) it.next()).getDescriptor());
                }
                a.j(a, new Gson().toJson(arrayList));
            } catch (IllegalStateException e) {
                e.printStackTrace();
                j.bi(new Object[]{e});
            }
            if (z) {
                y.by.getBridge().close();
            }
            if (abstractCollection != null) {
                l.put(a + "_FieldData", abstractCollection);
            } else {
                j.bi(new Object[]{"error", a + "\n" + a, new Gson().toJson(fieldMatcher)});
            }
            return abstractCollection;
        }
    }

    public static synchronized FieldDataList x(FieldMatcher fieldMatcher) {
        FieldDataList w;
        synchronized (c.class) {
            w = w(y.by.getBridge(), fieldMatcher);
        }
        return w;
    }

    public static synchronized MethodDataList y(DexKitBridge dexKitBridge, MethodMatcher methodMatcher) {
        boolean z;
        synchronized (c.class) {
            System.currentTimeMillis();
            String a = a.a();
            Object obj = l.get(a + "_MethodDataList");
            if (obj != null) {
                return (MethodDataList) obj;
            }
            JsonHookStatic jsonHookStatic = y.by;
            AbstractCollection abstractCollection = null;
            if (jsonHookStatic.getBridge() == null) {
                j.bi(new Object[]{"Bridge not initialized!"});
                return null;
            }
            if (jsonHookStatic.getBridge().isValid()) {
                z = false;
            } else {
                jsonHookStatic.setBridge(k ? DexKitBridge.create(jsonHookStatic.getClassLoader(), true) : DexKitBridge.create(jsonHookStatic.getLpparam().appInfo.sourceDir));
                dexKitBridge = jsonHookStatic.getBridge();
                z = true;
            }
            try {
                abstractCollection = a.h(a);
                if (abstractCollection == null) {
                    abstractCollection = dexKitBridge.findMethod(FindMethod.create().matcher(methodMatcher));
                }
                ArrayList arrayList = new ArrayList();
                Iterator it = abstractCollection.iterator();
                while (it.hasNext()) {
                    arrayList.add(((MethodData) it.next()).getDescriptor());
                }
                a.j(a, new Gson().toJson(arrayList));
            } catch (IllegalStateException e) {
                e.printStackTrace();
                j.bi(new Object[]{e});
            }
            if (z) {
                y.by.getBridge().close();
            }
            if (abstractCollection != null) {
                l.put(a + "_MethodDataList", abstractCollection);
            } else {
                j.bi(new Object[]{"error", a + "\n" + new Gson().toJson(methodMatcher)});
            }
            return abstractCollection;
        }
    }

    public static synchronized MethodDataList z(MethodMatcher methodMatcher) {
        MethodDataList y;
        synchronized (c.class) {
            y = y(y.by.getBridge(), methodMatcher);
        }
        return y;
    }
}
